#include "main.hh"

void
Main::treat_action (ActionRtsMove* act)
{
  c->move (act->vect_get ());
}

void
Main::treat_action (ActionRtsExit* act)
{
  (void) act;
  go = false;
}

void
Main::treat_action (ActionFpsMove* act)
{
  c->move (act->vect_get ());
}

void
Main::treat_action (ActionFpsExit* act)
{
  (void) act;
  go = false;
}

void
Main::treat_action (ActionRtsMoveObj* act)
{
  if (m->obj_select ()[0] != -1)
  {
    std::map<int, ObjAction*>::iterator it;
    for (int i = 0; i < m->select_size (); ++i)
      {
	it = obj_act_->find (m->obj_select ()[i]);
	if (it == obj_act_->end ())
	  (*obj_act_)[m->obj_select ()[i]] = new ObjAction ();

	(*obj_act_)[m->obj_select ()[i]]->add_move (act->vect_get ());
      }
  }
}

void
Main::treat_action (ActionRtsRotateObj* act)
{
  std::string str;

  if (m->obj_select ()[0] != -1)
  {
    std::map<int, ObjAction*>::iterator it;
    for (int i = 0; i < m->select_size (); ++i)
      {
	it = obj_act_->find (m->obj_select ()[i]);
	if (it == obj_act_->end ())
	  (*obj_act_)[m->obj_select ()[i]] = new ObjAction ();

	(*obj_act_)[m->obj_select ()[i]]->add_rotate (act->vect ());
      }
  }
}

void
Main::treat_action (ActionChat* act)
{
  (void) act;
  chat->switch_state ();
  k->chat_active_switch ();
  k->chat_enable_switch ();
}

void
Main::treat_action (ActionChatES* act)
{
  (void) act;
  chat->enable_switch ();
  k->chat_enable_switch ();
}

void
Main::treat_action (ActionChatDel* act)
{
  chat->erase_char ();
  delete act;
}

void
Main::treat_action (ActionChatAdd* act)
{
  chat->add_char (act->key_get ());
  delete act;
}

void
Main::treat_action (ActionSendText* act)
{
  std::string final = act->text_get ();

  final = '[' + player_name + "] > " + final;

  s->nm ()->send (RType::TEXT, std::string (final));
  delete act;
}

void
Main::treat_action (ActionNewMessage* act)
{
  chat->new_msg (act->text_get ());
  delete act;
}

void
Main::treat_action (ActionChatCurMove* act)
{

  if (act->move_get () == 1)
    chat->move_cursor_right ();
  else
    chat->move_cursor_left ();
  delete act;
}

void
Main::treat_action (ActionResetSelection* act)
{
  delete act;
  m = new Mouse (mh, s, c);
  k->mouse (m);
  s->disp ()->insert (std::make_pair ((size_t) m, boost::shared_ptr<Displayable> (m)));

}
